class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        # s = "abcabcbb"
        occ = set()
        n = len(s)
        ans = 0
        for i in range(n):
            rk = -1
            if s[i] in occ:
                occ.remove(s[i])
            while rk+1<n and s[rk+1] not in occ:
                occ.add(s[rk+1])
                rk+=1
            ans = max(ans,rk-i+1)
        return ans
print(Solution().lengthOfLongestSubstring("abcabcbb"))